<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./css/normal.css">
    <script src="./js/jquery.min.js" charset="utf-8"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script src="./js/utils.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">工序</a>
                <a>
                    <cite>电阻率</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end"></div>
                        <!--                        <div class="layui-inline layui-show-xs-block">-->
                        <!--                            <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input"></div>-->
                        <div class="layui-inline layui-show-xs-block">
                            <button type="button" class="layui-btn" id="search" lay-submit=""
                                    lay-filter="search"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn"
                            onclick="xadmin.open('添加记录','./normal-record-add.html?process=Resistivity',600,700,true)">
                        <i
                                class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body">
                    <h3>电阻率长期注意事项</h3>
                </div>
                <div id="importantMatter_long" class="layui-card-header">

                </div>
                <div class="layui-card-body ">
                    <table id="visual_inspection_table" class="layui-table layui-form"
                           lay-filter="visual_inspection_table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="visual_inspection_table_toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    window.onload = function () {
        getImportantMatter_long("Resistivity");
    };
</script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });

    });
</script>
<script>
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#visual_inspection_table'
            , height: 520
            , url: '/getAllRecord?process=Resistivity' //数据接口
            , page: true //开启分页
            , cols: [[
                {field: 'uuid', title: 'ID', hide: true},
                {field: 'workingshiftdate', title: '日期', sort: true},
                {
                    field: 'workingshift', title: '班次', templet: function (d) {
                        if (d.workingshift == 0) {
                            return '日班';
                        } else {
                            return '夜班';
                        }
                    }
                },
                {field: 'endshift', title: '交班人'},
                {field: 'startshift', title: '接班人'},
                {title: '操作', align: 'center', toolbar: '#visual_inspection_table_toolbar'} //这里的toolbar值是模板元素的选择器
            ]],
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                var result;
                // console.log(this);
                // console.log(JSON.stringify(res));
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                } else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            },
            // toolbar: '#visual_inspection_table_toolbar' //开启头部工具栏，并为其绑定左侧模板
            // , defaultToolbar: ['exports', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            //     title: '提示'
            //     , layEvent: 'LAYTABLE_TIPS'
            //     , icon: 'layui-icon-tips'
            // }]
        });

        table.on('tool(visual_inspection_table)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）


            if (layEvent === 'detail') { //查看
                //do somehing
                console.log(data);
                var d = "?uuid=" + data.uuid + "&process=" + data.process + "&date=" + data.workingshiftdate + "&workingShift=" + data.workingshift;
                xadmin.open('电阻率记录' + data.workingshiftdate, './normal-record-detail.html' + d, 100, 700, true);
            } else if (layEvent === 'del') { //删除
                var workingShift = "";
                if (data.workingshift == 0) {
                    workingShift = "日班";
                } else if (data.workingshift == 1) {
                    workingShift = "夜班";
                }
                layer.confirm('确认删除' + data.workingshiftdate + workingShift + '的记录吗?', function (index) {
                    //向服务端发送删除指令
                    $.ajax({
                        url: "/deleteRecord",    //请求的url地址
                        dataType: "json",   //返回格式为json
                        data: data,    //参数值
                        type: "GET",   //请求方式
                        success: function (req) {
                            //请求成功时处理
                            layer.msg('已经删除' + data.workingshiftdate + workingShift + '的记录');
                        }
                    });
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                });
            } else if (layEvent === 'LAYTABLE_TIPS') {
                layer.alert('Hi，头部工具栏扩展的右侧图标。');
            }
        });

        $("#search").on('click', function () {
            var start = $("#start").val();
            var end = $("#end").val();
            table.reload('visual_inspection_table', {
                method: 'post'
                , url: '/searchByDate'
                , where: {
                    'start': start,
                    'end': end,
                    'process': 'Resistivity'
                }
                , page: {
                    curr: 1
                }
            });
        });
    });
</script>
</html>